package com.fjec.base.service.impl;

import com.fjec.base.entity.SysParam;
import com.fjec.base.mapper.SysParamMapper;
import com.fjec.base.mapper.SysParamMapperExt;
import com.fjec.base.service.ISysParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjec.common.setting.Setting;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 005.系统参数表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2020-08-31
 */
@Service
@Transactional
public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, SysParam> implements ISysParamService {

    @Resource
    private SysParamMapperExt mapperExt;

    @Override
    @Cacheable(value = "systemSetting", key = "'fjec:system:setting:key'")
    public Map<String, Object> getSysSetting() {
        return doGetSysSetting();
    }

    @Override
    @CachePut(value = "systemSetting", key = "'fjec:system:setting:key'")
    public Map<String, Object> cacheSysSetting() {
        return doGetSysSetting();
    }

    public Map<String, Object> doGetSysSetting() {
        Map<String, Object> resultMap = new HashMap<>();
        List<SysParam> entityList = mapperExt.getAll();
        for (SysParam entity : entityList) {
            resultMap.put(entity.getParamKey(), entity.getParamValue().get("value"));
        }
        return resultMap;
    }
}
